var fs = require('fs');
var http = require('http');
var https = require('https');
var path = require('path');

var privatekey = fs.readFileSync('./key/privatekey.pem', 'utf8');
var certificate = fs.readFileSync('./key/certificate.pem', 'utf8');
var credentials = {
    key: privatekey,
    cert: certificate
}

var httpServer = http.createServer();
var httpsServer = https.createServer(credentials);

var port = 81;
var sslPort = 443;

let data = fs.readFileSync(path.resolve(__dirname, './product.json'));

httpServer.on('request', (req, res)=>{
    res.setHeader('Content-Type','text/plain;charset=utf-8');
    res.end(data);
});

httpsServer.on('request', (req, res)=>{
    res.setHeader('Content-Type','text/plain;charset=utf-8');
    res.end(data);
});

httpServer.listen(port, ()=>{console.log('HTTP 网站启动，端口号：81')});

httpsServer.listen(sslPort, ()=>{console.log('HTTPS 网站启动，端口号：443')});
